package ACM.meituan2;

/**
 * @Author wwk
 * @DATE 2022/8/27 17:20
 */
import java.util.*;

import java.util.*;

public class fifth {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();  //事件数
        int k = scanner.nextInt();  // 种类数
        int T = scanner.nextInt();   //摸猫时间

        int[] toys = new int[k];
        int[] nums = new int[k];  //对应玩具的数量
        for (int i = 0; i <k; i++){
            toys[i] = scanner.nextInt();
        }
        int[] events = new int[n];
        for (int i = 0; i < n; i++){
            events[i] = scanner.nextInt();
        }
        PriorityQueue<Integer> queue = new PriorityQueue<>();  //最小堆,只加时间
        //dp[i][0]表示用玩具，dp[i][1]表示摸
        int time = 0;
        for (int i = 0; i <n;i++){
            int event = events[i];
            //遇到猫
            if(event==0){
                if(queue.size()==0){
                    time += T;
                }else{
                    time += queue.peek() > T ? T : queue.poll();
                }

            } else{
                //捡玩具,玩具数量+1
                queue.offer(toys[event-1]);
            }
        }
        System.out.println(time);
    }

    //每次从玩具中，找到一个时间最少的且有数量的下标，如果都为空则返回-1
    private static int getMin(int[] toys, int[] nums){
        int min = -1;
        int num = Integer.MAX_VALUE;  //最小时间
        for(int i = 0;i<nums.length;i++){
            //找到一个时间最少的且有数量的下标
            if(nums[i]>0 && toys[i]<num){
                num = toys[i];
                min = i;
            }
        }

        return min;
    }
}

